{% extends "layout.html" %}
{% block content %}
    <div class="x-body layui-anim layui-anim-up">
        <form class="layui-form">
			<table class="layui-table">
				<tbody>
                    <tr>
						<th><span class="x-red">*</span>通道名称</th>
						<td colspan="3">
                            <input type="text" id="name" name="name" required="" lay-verify=""
                            autocomplete="off" class="layui-input" disabled>
                        </td>
                    </tr>
                    <tr>
						<th><span class="x-red">*</span>状态</th>
						<td colspan="3">
                            <div id="dataSimulator_state"></div>
                        </td>
                    </tr>
					<tr>
						<td colspan="2" style="text-align: center;">
                            <button id="start" class="layui-btn layui-btn-disabled" lay-filter="start" lay-submit="">
                                启动
                            </button>
                        </td>
						<td colspan="2" style="text-align: center;">
                            <button id="stop" class="layui-btn layui-btn-disabled" lay-filter="stop" lay-submit="">
                                停止
                            </button>
						</td>
					</tr>
                </tbody>
            </table>
        </form>
    </div>
    <script>
        var dataSimulator_id=GetQueryString('dataSimulator_id');
        var dataSimulator_state=null;
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            var form = layui.form
            ,layer = layui.layer;
            var $=layui.jquery;

            //监听提交
            form.on('submit(start)', function(data){
                if(dataSimulator_id==null){
                    layui.alert("错误操作");
                    return;
                }
                $.ajax({
                    url:'rundataSimulator',
                    type:'POST',
                    dataType:'json',
                    data:{
                        dataSimulator_id:dataSimulator_id
                    },
                    success:function(data){
                        if(data.code==0){
                            layer.msg('操作成功!');
                            // layer.alert("操作成功");
                            $("#stop").removeClass("layui-btn-disabled");
                            $("#start").addClass("layui-btn-disabled");
                            $("#dataSimulator_state").html("已运行");
                        }else{
                            layer.msg(data.msg);
                        }
                    }
                });
                return false;
            });
            //监听提交
            form.on('submit(stop)', function(data){
                if(dataSimulator_id==null){
                    layui.alert("错误操作");
                    return;
                }
                $.ajax({
                    url:'stopdataSimulator',
                    type:'POST',
                    dataType:'json',
                    data:{
                        dataSimulator_id:dataSimulator_id
                    },
                    success:function(data){
                        if(data.code==0){
                            layer.msg('操作成功!');
                            // layer.alert("操作成功");
                            $("#start").removeClass("layui-btn-disabled");
                            $("#stop").addClass("layui-btn-disabled");
                            $("#dataSimulator_state").html("未运行");
                        }
                    }
                });
                return false;
            });
            layer.ready(function(){
                if(dataSimulator_id!=null){
                    data={'dataSimulator_id':dataSimulator_id};
                    $.ajax(
                    {
                        url:'readdataSimulator'
                        ,type:'POST'
                        ,dataType:'json'
                        ,data:data
                        ,success:function(data){
                            //设置内容
                            if(data.code==0){
                                $('#name').val(data.data[0].name);
                                layui.form.render();
                            }
                        }
                    });
                    $.ajax(
                    {
                        url:'checkdataSimulatorState'
                        ,type:'POST'
                        ,dataType:'json'
                        ,data:data
                        ,success:function(data){
                            //设置内容
                            if(data.code==0){
                                $("#stop").removeClass("layui-btn-disabled");
                                $("#dataSimulator_state").html("已运行");
                            }else{
                                $("#start").removeClass("layui-btn-disabled");
                                $("#dataSimulator_state").html("未运行");
                            }
                        }
                    });
                }
            });
        });
    </script>
{% endblock %}